package com.example.mycarcalling.activity;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AlertDialog;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.mycarcalling.R;


public class GetOffConfirmDialog {

    public final static String TAG = GetOffConfirmDialog.class.getSimpleName();

    private AlertDialog getOffConfirmDialog = null;
    private Button btn_cancel = null;
    private Button btn_confirm = null;
    private ImageView iv_get_off = null;

    private View inflate = null;

    public Button getBtn_cancel() {
        return btn_cancel;
    }

    public Button getBtn_confirm() {
        return btn_confirm;
    }

    public ImageView getIv_get_in() {
        return iv_get_off;
    }

    public GetOffConfirmDialog(Context context){
        inflate = View.inflate(context, R.layout.dialog_get_off_confirm,null);


        getOffConfirmDialog = new AlertDialog.Builder(context)
                .setView(inflate)
                .create();

        btn_cancel = inflate.findViewById(R.id.btn_cancel_get_off_dialog);
        btn_confirm = inflate.findViewById(R.id.btn_confirm_get_off_dialog);
        iv_get_off = inflate.findViewById(R.id.iv_get_off_dialog);

        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });



        //设置图片圆角角度
        RoundedCorners roundedCorners = new RoundedCorners(100);
        //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 300);

        Glide.with(context)
                .asGif()
                .load(R.mipmap.get_off)
                .apply(options)
                .into(iv_get_off);
    }

    public void show() {
        getOffConfirmDialog.show();
    }

    public void dismiss() {
        getOffConfirmDialog.dismiss();
    }

}
